﻿using System.Collections;
using System.Collections.Generic;
using TTGameEngine;
using UnityEngine;

namespace AliveCard {
/*
 * 负责整体游戏逻辑。
 *
 *
 */
public class GamePlay : MonoBehaviour {
    public static GamePlay Self;

    public Transform m_mapRoot;
    public GameObject m_heroPrefab;
    public Room m_firstRoom;
    [ReadOnly]
    public CameraControl m_mainCameraCtrl;

    void Awake() {
        Self = this;
        init();
    }

    private void Start() {

        StartGame();
    }

    public void init() {
        m_mainCameraCtrl = GameObject.FindObjectOfType<CameraControl>();
    }

    // Use this for initialization
    void StartGame() {
        //UI
        UIMainData uidata = new UIMainData();
        uidata.InitWithOptions(GameConfig.Ins.InitOption);
        UIManager.Ins.ShowUI(UIFormID.UI_Main, uidata);
        //房间布置
        //RoomManager.Ins.ActiveAllRoomTrigger(false);
        m_firstRoom.IsLock = false;

        //mark:test
        RoomManager.Ins.GetRoomByIdx(1).IsLock = false;

        //create hero
        GameObject heroObj = ObjectRecycler.Instance.InstantiatePrefab(m_heroPrefab, Vector3.zero, Quaternion.identity);
        heroObj.transform.parent = m_mapRoot;

        ACPuppet hero = heroObj.GetComponent<ACPuppet>();
        ACObjectManager.Ins.SetHero(hero);
        RoomManager.Ins.MoveToRoomImm(m_firstRoom);

        //lock Camera
        m_mainCameraCtrl.LockTarget(hero.objTF);
        //等主角放置位置OK后，再开启触发器。
        RoomManager.Ins.ActiveAllRoomTrigger(true);

        //！游戏准备完毕！

        TTEventSystem.Ins.RaiseEvent(GameEventID.GE_StartGame);



    }

}
}